<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="queryForm" :model="listQuery" :rules="rules" label-position="left">
        <el-form-item size="mini" prop="title" style="float: left;">
          <el-input v-model="searchData.username" placeholder="用户名称" class="filter-item" style="width: 160px;margin-right:5px;"></el-input>
        </el-form-item>
        <el-form-item size="mini" prop="type_sub_id" style="float: left;">
          <el-select v-model="searchData.flow_type" placeholder="请选择" style="width: 160px;margin-right:5px;">
            <el-option label="所有" value=""></el-option>
            <el-option
              v-for="item in flowTypeOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="mini" style="float: left;">
          <el-button v-waves size="mini" class="filter-item" type="primary" icon="el-icon-search" @click="getList">查询</el-button>
          <el-button v-waves size="mini" class="filter-item" type="danger" @click="resetQueryForm('queryForm')">重置</el-button>
        </el-form-item>
        <div style="float: right;margin-right: 60px">
          <el-button v-waves size="mini" class="filter-item" type="primary" icon="el-icon-plus" @click="handleAdd()">添加景点</el-button>
        </div>
      </el-form>
    </div>
    <el-table v-loading="listLoading" size="mini" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="ID" width="70">
        <template slot-scope="{row}">
          <span>{{ row.Id }}</span>
        </template>
      </el-table-column>
      <el-table-column width="160px" align="center" label="用户">
        <template slot-scope="{row}">
          <span>{{ row.Username }}</span>
        </template>
      </el-table-column>
      <el-table-column width="160px" align="center" label="流转类型">
        <template slot-scope="{row}">
          <span>{{ row.TypeName }}</span>
        </template>
      </el-table-column>
      <el-table-column width="80px" align="center" label="类型">
        <template slot-scope="{row}">
          <span v-if="row.FlowType === 'in'">转入</span>
          <span v-if="row.FlowType === 'out'" style="color: red;">转出</span>
        </template>
      </el-table-column>
      <el-table-column width="120px" align="center" label="流转金额">
        <template slot-scope="{row}">
          <span>{{ row.Amount }}</span>
        </template>
      </el-table-column>
      <el-table-column width="150px" align="center" label="流转前">
        <template slot-scope="{row}">
          <span>{{ row.BeforeBalance }}</span>
        </template>
      </el-table-column>
      <el-table-column width="150px" align="center" label="流转后">
        <template slot-scope="{row}">
          <span>{{ row.Balance }}</span>
        </template>
      </el-table-column>
      <el-table-column width="150px" align="center" label="积分">
        <template slot-scope="{row}">
          <span>{{ row.Score }}</span>
        </template>
      </el-table-column>
      <el-table-column width="160px" align="center" label="管理员">
        <template slot-scope="{row}">
          <span>{{ row.FromAdminId }}</span>
        </template>
      </el-table-column>
      <el-table-column width="150px" align="center" label="操作时间">
        <template slot-scope="{row}">
          <span>{{ parseTime(row.ProcessTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="{row}">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-money"
            @click="handleDetailWindow(row)"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="searchData.page_index" :limit="searchData.page_size" :page-sizes="pageSizes" @pagination="getList" />

    <!-- 弹窗  -->
    <el-dialog title="流转详情" :visible.sync="dialogDetailVisible">
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">
          Cancel
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { accountFlowReportList } from '@/api/user'
import waves from '@/directive/waves'
import { parseTime } from '@/utils/index'
import Pagination from '@/components/Pagination'

export default {
  name: 'AccountFlowReportList',
  directives: { waves },
  components: { Pagination },
  data() {
    return {
      list: [],
      pageSizes: [10, 15, 20, 25, 30, 50, 100],
      listLoading: true,
      total: 0,
      searchData: {
        page_index: 1,
        page_size: 15,
        username: '',
        flow_type: ''
      },
      flowTypeOptions: [],
      dialogDetailVisible: false,
      rules: {
        flow_type: [{ required: false, message: '需要选择类型', trigger: 'blur' }],
        username: [
          { pattern: /^[a-zA-Z0-9]{6,24}$/, type: 'string', message: '用户名只能 [字母,数字],组成 6 - 24位', trigger: 'blur' },
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      accountFlowReportList(this.searchData).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.flowTypeOptions = response.data.flow_type_options
        setTimeout(() => {
          this.listLoading = false
        }, 1 * 300)
      })
    },
    handleFilter() {
      this.searchData.page_index = 1
      this.getList()
    },
    handleDetailWindow() {

    },
    parseTime(time, format) {
      return parseTime(time, format)
    }
  }
}
</script>
